<?php
namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;
class Laststudent extends Backend
{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\FormStudent;

    }

    public function index()
    {
        $this->request->filter(['strip_tags']);

        if ($this->request->isAjax()) {
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $sqlcnt = 'select count(1) cnt from (select max(id) id from qa_form_student group by sid) t';
            $cnt = Db::query($sqlcnt);
            $total = $cnt[0]['cnt'];

            $sql = "select * from qa_form_student fs,
                (select max(id) tid from qa_form_student group by sid limit $offset, $limit) t
                where fs.id = t.tid";

            $rows = Db::query($sql);

            $result = array("total" => $total, "rows" => $rows);

            return json($result);

        }
        return $this->view->fetch();
    }

}